<template>
  <div class="home">
    <div class="announcement">
      <SvgIcon class="icon" icon-class="公告" />
      欢迎光临！部署文档：{{ webInfo.getDeployUrl }}
    </div>
    <div class="content">
      <div class="website-info">
        <WebMaster />
        <ArticleTag @update-article="getArticleList"/>
        <WebSiteInfo />
      </div>
      <div class="home-article">
        <div class="top">
          <TopCategory @change-category="getArticleList"/>
          <TopArticle :article="topArticle"/>
        </div>
        <div class="article-content">
          <div class="switchover-article-arrange">
            <div class="experiences">
              <div class="experience-title">
                <SvgIcon class-name="icon" icon-class="心得" />
                <span class="text">心得</span>
              </div>
              <p>我热爱开发，设计，创新，享受生活，以及在未知领域中探索...</p>
            </div>
            <div class="switchover">
              <div :class="{'icon-button': true,'select': !isList}" @click="switchover">
                <SvgIcon class-name="icon" icon-class="九宫格"/>
              </div>
              <div :class="{'icon-button': true,'select': isList}" @click="switchover">
                <SvgIcon class-name="icon" icon-class="list"/>
              </div>
            </div>
          </div>
          <div class="article-list">
            <ArticleCard v-for="item in articleList" :key="item.id" :article="item"/>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import WebMaster from "@/components/webinfo/WebMaster.vue";
import SvgIcon from "@/components/common/SvgIcon.vue";
import {webInfoStore} from "@/store";
import ArticleTag from "@/components/webinfo/ArticleTag.vue";
import TopArticle from "@/components/top/TopArticle.vue";
import TopCategory from "@/components/top/TopCategory.vue";
import WebSiteInfo from "@/components/webinfo/WebSiteInfo.vue";
import {onBeforeMount, onMounted, ref} from "vue";
import {articleApi} from "@/api/blog/articleApi.ts";
import ArticleCard from "@/components/article/ArticleCard.vue";
const webInfo = webInfoStore()
const isList = ref(false)
const topArticle = ref()
const articleList = ref()
const getArticleList = (article:Partial<ArticleSearch>) => {
  articleApi.getArticlePage(article).then((res)=>{
    articleList.value = res.data.records
  })
}
const switchover = () => {
  isList.value = !isList.value
}
onBeforeMount(()=>{
  articleApi.getTopArticle().then((res)=>{
    if (res.data){
      topArticle.value = res.data
    }
  })
})
onMounted(()=>{
  getArticleList({current:1, size:10})
})
</script>

<style lang="less" scoped>
.home {
  width: 100%;
  height: 100%;
}
.announcement {
  width: 100%;
  height: 48px;
  border-radius: 8px;
  background: #ffffffe6;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  font-size: 14px;
  color: #333333;
  .icon {
    margin: 16px;
    width: 16px;
    height: 16px;
  }
}
.content {
  display: flex;
  justify-content: center;
  gap: 120px;
  .website-info {
    width: 300px;
  }
}
.article-list {
  width: 100%;
  margin-top: 16px;
  display: flex;
  //justify-content: space-between;
  flex-wrap:wrap;
  column-gap: calc(50% - 3/2 * 310px);
  .article-card {
    margin-top: 16px;
  }
}
.switchover-article-arrange{
  margin-top: 16px;
  display: flex;
  justify-content: space-between;
  .experiences {
    width: 100%;
    height: 32px;
    border-radius: 8px;
    border-width: 1.5px;
    border-style: solid;
    border-image-source: linear-gradient(0deg, #f7c9d633 9.38%, #f7c9d600 120.31%);
    border-image-slice: 1;
    box-sizing: border-box;
    background: #fff6f9;
    display: flex;
    .experience-title {
      display: flex;
      align-items: center;
      position: relative;
      .icon{
        margin-left: 24px;
        width: 56px;
        height: 26px;
      }
      & > span{
        position: absolute;
        top: 50%;
        left: 66px;
        font-size: 14px;
        color: #333333;
        transform: translate(-50%, -50%);
        z-index: 1;
        width: 33.8px;
      }
    }
    & > p{
      margin-left: 13px;
      line-height: 32px;
      color: #333333;
      font-size: 14px;
      white-space: nowrap;      /* 确保文本不换行 */
      overflow: hidden;         /* 超出容器部分隐藏 */
      text-overflow: ellipsis;  /* 超出部分显示省略号 */
    }
  }
  .switchover {
    margin-left: 12px;
    height: 32px;
    border-radius: 8px;
    background: #ffffff;
    display: flex;
    align-items: center;
    padding: 3px;
    box-sizing: border-box;
    .icon-button{
      width: 26px;
      height: 26px;
      border-radius: 6px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #333333;
      .icon{
        width: 16px;
        height: 16px;
      }
      &.select{
        background: #f7c9d6;
        color: #EB5C88;
      }
    }
  }
}
@media screen and (max-width: 768px) {
  .content {
    display: flex;
    flex-direction: column;
    .website-info {
      //width: 100%;
      margin: 0 auto; /* 居中 */
    }
    .home-article{
      .top {
        margin-top: 15px;
      }
      .article-list{
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 15px;
      }
    }
  }
  .switchover-article-arrange{
    .experiences{
      max-width: 75%;
      &>p{
        font-size: 12px !important;
      }
    }
  }
}
@media screen and  (max-width: 768px) {
  .article-list{
    /* grid布局 两端对齐,最后一行左对齐*/
    display: grid;
    /* 1fr | px 这是将网格分为几列，1fr是自适配单位，可以当成栅格*/
    grid-template-columns: 1fr 1fr 1fr;
    column-gap: 17px;
  }
}
//@media screen and  (min-width: 1024px) {
@media screen and  (min-width: 2000px) {
  .article-list{
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    column-gap: calc((100% - 3 * 310px) / 2);
  }
}
//@media screen and  (min-width: 1280px) {
//  .article-list{
//    display: grid;
//    grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
//    gap: calc((100% - 5 * 310px) / 4);
//  }
//}
</style>
